import requests
import time
from datetime import datetime, timedelta

# 请求的URL和参数
url = "http://jw.hitsz.edu.cn/Xsxk/addGouwuche"
payload = "cxsfmt=0&p_pylx=2&mxpylx=2&p_sfgldjr=0&p_sfredis=0&p_sfsyxkgwc=0&p_xktjz=rwtjzyx&p_chaxunxh=&p_gjz=&p_skjs=&p_xn=2024-2025&p_xq=2&p_xnxq=2024-20252&p_dqxn=2024-2025&p_dqxq=1&p_dqxnxq=2024-20251&p_xkfsdm=xyjsxk-y-y&p_xiaoqu=&p_kkyx=&p_kclb=&p_xkxs=&p_dyc=&p_kkxnxq=&p_id=248F950CAF558A90E0630C18F80A2B4F&p_sfhlctkc=0&p_sfhllrlkc=0&p_kxsj_xqj=&p_kxsj_ksjc=&p_kxsj_jsjc=&p_kcdm_js=&p_kcdm_cxrw=&p_kc_gjz=&p_xzcxtjz_nj=&p_xzcxtjz_yx=&p_xzcxtjz_zy=&p_xzcxtjz_zyfx=&p_xzcxtjz_bj=&p_sfxsgwckb=1&p_skyy=&p_chaxunxkfsdm=&pageNum=1&pageSize=28"
headers = {
    'Accept': '*/*',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Connection': 'keep-alive',
    'Content-Length': '533',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie': '_gscu_651000777=25545213mkzar524; route=cb5f888c9cb0d85c260c8284847d46e6; JSESSIONID=E3996A80A4D155AD573C3D24A47E57E0',
    'DNT': '1',
    'Host': 'jw.hitsz.edu.cn',
    'Origin': 'http://jw.hitsz.edu.cn',
    'Referer': 'http://jw.hitsz.edu.cn/Xsxk/query/2',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0',
    'X-Requested-With': 'XMLHttpRequest'
}


# 获取当前时间并计算当天上午10点的时间
def get_target_time():
    now = datetime.now()
    target_time = datetime(now.year, now.month, now.day, 10, 0, 0)
    return target_time


# 等待到目标时间
def wait_until(target_time):
    while datetime.now() < target_time:
        time.sleep(1)


# 定时任务
if __name__ == "__main__":
    target_time = get_target_time()
    print(f"将于 {target_time} 开始发送请求...")
    wait_until(target_time)

    print("开始发送请求...")
    while True:
        try:
            response = requests.post(url, headers=headers, data=payload)
            print(f"响应状态码: {response.status_code}, 响应内容: {response.text}")
        except Exception as e:
            print(f"请求发生错误: {e}")

        # 每隔10秒发送一次请求
        time.sleep(300)
